<template>
  <div
    class="w-full border-solid border-1px p-10px m-10px flex flex-col gap-10px"
  >
    <div>{{ title }}</div>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="Activity name">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="Activity zone">
        <el-select v-model="form.region" placeholder="please select your zone">
          <el-option label="Zone one" value="shanghai" />
          <el-option label="Zone two" value="beijing" />
        </el-select>
      </el-form-item>
      <el-form-item label="Activity time">
        <el-col :span="11">
          <el-date-picker
            v-model="form.date1"
            type="date"
            placeholder="Pick a date"
            style="width: 100%"
          />
        </el-col>
        <el-col :span="2" class="text-center">
          <span class="text-gray-500">-</span>
        </el-col>
        <el-col :span="11">
          <el-time-picker
            v-model="form.date2"
            placeholder="Pick a time"
            style="width: 100%"
          />
        </el-col>
      </el-form-item>
      <el-form-item label="Instant delivery">
        <el-switch @change="handleChange" v-model="form.delivery" />
      </el-form-item>
      <el-form-item label="Activity type">
        <el-checkbox-group v-model="form.type">
          <el-checkbox value="Online activities" name="type">
            Online activities
          </el-checkbox>
          <el-checkbox value="Promotion activities" name="type">
            Promotion activities
          </el-checkbox>
          <el-checkbox value="Offline activities" name="type">
            Offline activities
          </el-checkbox>
          <el-checkbox value="Simple brand exposure" name="type">
            Simple brand exposure
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="Resources">
        <el-radio-group v-model="form.resource">
          <el-radio value="Sponsor">Sponsor</el-radio>
          <el-radio value="Venue">Venue</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="Activity form">
        <el-input v-model="form.desc" type="textarea" />
      </el-form-item>
    </el-form>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">确定</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </div>
</template>

<script lang="ts" setup>
import { ElInput, ElMessage } from "element-plus";

const props = defineProps({
  type: String,
});
const title = computed(() => (props.type === "add" ? "新增" : "编辑"));
const form = ref({
  name: "",
  region: "",
  date1: "",
  date2: "",
  delivery: false,
  type: [],
  resource: "",
  desc: "",
});
const onSubmit = () => {
  if (props.type === "add") {
    ElMessage({
      message: "新增成功",
      type: "success",
    });
    // 参数处理，数据处理
    // 调用新增接口
    return;
  }
  if (props.type === "edit") {
    // 参数处理，数据处理
    // 调用编辑接口
    ElMessage({
      message: "修改成功",
      type: "success",
    });
    return;
  }
};
onMounted(() => {
  if (props.type === "edit") {
    //调用查询接口回显
    form.value = {
      name: "123456",
      region: "shanghai",
      date1: "2025-06-12T16:00:00.000Z",
      date2: "2025-06-19T08:15:28.000Z",
      delivery: true,
      type: ["Promotion activities", "Simple brand exposure"],
      resource: "Venue",
      desc: "哈哈哈",
    };
  }
});
const handleChange = (v) => {
  if (v) {
    if (props.type === "add") {
      ElMessage({
        message: "调用新增时的业务接口",
        type: "info",
      });
    } else if (props.type === "edit") {
      ElMessage({
        message: "调用编辑时的业务接口",
        type: "success",
      });
    }
  }
};
</script>
